package com.example.demo;

import com.example.demo.chat_room.NettyServerStart;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.annotation.Order;

@SpringBootApplication
// springboot启动后第一顺位启动
@Order(1)
/**
 * 实现CommandLineRunner接口的类
 * 会在springboot启动后的第一时间根据Order注解的升序开始执行里面的run方法
 * 虽然启动类中的CommandLineRunner一定会是第一个,但最好还是写上Order
 */
public class DemoApplication implements CommandLineRunner {

    @Autowired
    NettyServerStart nettyServerStart;

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    /**
     * 启动Netty服务器
     * @param args
     * @throws Exception
     */
    @Override
    public void run(String... args) throws Exception {
        new Thread(nettyServerStart).start();
    }
}